package br.biofoco.p2p.bootstrap;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.concurrent.Callable;

public class ExecuterBLAST implements Callable<String> {

	private Process p;
	String command = null;
	
	public ExecuterBLAST(Process p, String command){
		this.p = p;
		this.command = command;
	}
	
	@Override
	public String call() throws Exception {
		
			try {
				
				p = Runtime.getRuntime().exec(command);
				
				InputStream is = p.getInputStream();
				BufferedReader br = new BufferedReader(
						new InputStreamReader(is));
				String line = null;
				StringBuilder sb = new StringBuilder();
				while ((line = br.readLine()) != null) {
					sb.append(line);
				}

				BufferedReader error = new BufferedReader(new InputStreamReader(p.getErrorStream()));
				String line2 = null;
				StringBuilder sb2 = new StringBuilder();
				while ((line2 = br.readLine()) != null) {
					sb.append(line2);
				}
				
				return sb.toString();
			} catch (Exception e) {
				e.printStackTrace();
				throw new RuntimeException(e);
			}

		
	}
		
	public Process getProcessBlast(){
		return this.p;
	}

}
